package com.sk.weichat.ui.me.wallet;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.util.Log;
import android.view.View;
import android.view.WindowManager;
import android.widget.TextView;

import com.sk.weichat.R;
import com.sk.weichat.ui.base.BaseActivity;
import com.sk.weichat.util.ToastUtil;
import com.sk.weichat.view.PasswordInputEditText;
import com.xuan.xuanhttplibrary.okhttp.HttpUtils;
import com.xuan.xuanhttplibrary.okhttp.callback.BaseCallback;
import com.xuan.xuanhttplibrary.okhttp.result.ObjectResult;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import io.reactivex.Observer;
import io.reactivex.disposables.Disposable;
import okhttp3.Call;

public class ResetPayPwdNewActivity extends BaseActivity {
    private final static int request_confirm_pswd = 6451;
    PasswordInputEditText edtPswd;
    boolean isFirst = false;
    public static final String FIRST_SET_PSWD = "ResetPayPwdNewActivity_FIRST_SET_PSWD"; //第一次设置密码

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_reset_pay_pwd_new);
        edtPswd = findViewById(R.id.edt_pswd);
        if (getIntent() != null && getIntent().hasExtra(FIRST_SET_PSWD)) {
            isFirst = getIntent().getBooleanExtra(FIRST_SET_PSWD, false);
        }
        if (isFirst) {
            TextView tvTips = findViewById(R.id.tv_tips);
            tvTips.setText(getString(R.string.input_new_pswd));
        }
        TextView tvTitle = findViewById(R.id.tv_title_center);
        tvTitle.setText(getString(R.string.reset_pwd_title));
        findViewById(R.id.iv_title_left).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        edtPswd.setTextWatcher(new Observer<CharSequence>() {
            @Override
            public void onSubscribe(Disposable d) {

            }

            @Override
            public void onNext(CharSequence charSequence) {
                Log.e("lzs", "charSequence:" + charSequence);
                String pswd = charSequence.toString();
                if (pswd.length() == 6) {
                    ResetPayPwdConfirmActivity.startResetPayPwdConfirmActivityForResult(pswd, request_confirm_pswd, ResetPayPwdNewActivity.this);
                }
            }

            @Override
            public void onError(Throwable e) {

            }

            @Override
            public void onComplete() {

            }
        });
        //弹出键盘输入
        getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
    }


    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        if (requestCode == request_confirm_pswd && resultCode == Activity.RESULT_OK) {
            setResult(Activity.RESULT_OK);
            finish();
        }
        if (requestCode == request_confirm_pswd && resultCode == Activity.RESULT_CANCELED) {
            edtPswd.setText("");
        }
    }
}
